﻿using System;
using KKSG;
using UnityEngine;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient
{
	// Token: 0x02000EEA RID: 3818
	internal class XSelectcharStage : XCharStage
	{
		// Token: 0x0600CAC4 RID: 51908 RVA: 0x002E0114 File Offset: 0x002DE314
		public XSelectcharStage() : base(EXStage.SelectChar)
		{
			this._turn_interval = XSingleton<XGlobalConfig>.singleton.ProShowTurnInterval;
			this._turn_update = 0f;
		}

		// Token: 0x0600CAC5 RID: 51909 RVA: 0x002E0170 File Offset: 0x002DE370
		public override void OnEnterStage(EXStage eOld)
		{
			base.OnEnterStage(eOld);
			CombineMeshTask.s_CombineMatType = ECombineMatType.EIndependent;
			XSingleton<XResourceLoaderMgr>.singleton.DelayLoad = false;
			if (this._eStage != eOld)
			{
				this._auto_enter = false;
			}
			this._character_show = false;
			this._prelusive = true;
			if (eOld == EXStage.Login)
			{
				//zcg 跳过 XSingleton<XCutScene>.singleton.Start("CutScene/first2second_slash_show", false, true);
				this._token2 = XSingleton<XTimerMgr>.singleton.SetTimer(0.5f/*XSingleton<XCutScene>.singleton.Length*/, new XTimerMgr.ElapsedEventHandler(this.PresentDone), null);
			}
			else
			{
				this.ReLogined();
				XSingleton<XTutorialMgr>.singleton.Uninit();
			}
			XSingleton<XClientNetwork>.singleton.XLoginStep = XLoginStep.EnterGame;
		}

		// Token: 0x0600CAC6 RID: 51910 RVA: 0x002E0224 File Offset: 0x002DE424
		public override void OnLeaveStage(EXStage eNew)
		{
			base.OnLeaveStage(eNew);
			this._character_show = false;
			XSingleton<XTimerMgr>.singleton.KillTimer(this._token2);
			XSingleton<XTimerMgr>.singleton.KillTimer(this._token3);
			CombineMeshTask.s_CombineMatType = ECombineMatType.ECombined;
			XSingleton<XResourceLoaderMgr>.singleton.DelayLoad = true;
		}

		// Token: 0x0600CAC7 RID: 51911 RVA: 0x002E0274 File Offset: 0x002DE474
		public void ReLogined()
		{
			this._auto_enter = false;
			this._cur_tag = 0;
			DlgBase<XSelectCharView, SelectCharWindowBehaviour>.singleton.SwitchProfession(-1);
			//zcg XSingleton<XCutScene>.singleton.Start("CutScene/second_slash_show", false, true);
			XSingleton<XLoginDocument>.singleton.ShowSelectCharGerenalUI();
			this._prelusive = false;
		}

		// Token: 0x0600CAC8 RID: 51912 RVA: 0x002E02C0 File Offset: 0x002DE4C0
		public static void ShowBillboard(XDummy dummy)
		{
			int num = -1;
			int.TryParse(dummy.EngineObject.Tag, out num);
			if (num < 0 || num - 1 >= XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.PlayerBriefInfo.Count)
			{
				XSingleton<XDebug>.singleton.AddErrorLog("Character tag ", dummy.EngineObject.Tag, " exceeded server PlayerBriefInfo count.", null, null, null);
			}
			else
			{
				RoleBriefInfo roleBriefInfo = XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.PlayerBriefInfo[num - 1];
				if (roleBriefInfo != null)
				{
					XSingleton<XGameUI>.singleton.HpbarRoot.gameObject.SetActive(true);
					XSingleton<XGameUI>.singleton.NpcHpbarRoot.gameObject.SetActive(true);
					if (dummy.BillBoard == null)
					{
						dummy.BillBoard = (XSingleton<XComponentMgr>.singleton.CreateComponent(dummy, XBillboardComponent.uuID) as XBillboardComponent);
						dummy.BillBoard.AttachDummyBillboard(roleBriefInfo.name, roleBriefInfo.level, (int)((int)roleBriefInfo.type % /*(RoleType)*/10));
					}
					else
					{
						dummy.BillBoard.AttachDummyBillboard(roleBriefInfo.name, roleBriefInfo.level, (int)((int)roleBriefInfo.type % /*(RoleType)*/10));
					}
					dummy.BillBoard.SetSelectCharStageScale();
				}
			}
		}

		// Token: 0x0600CAC9 RID: 51913 RVA: 0x002E0404 File Offset: 0x002DE604
		public override void Update(float fDeltaT)
		{
			base.Update(fDeltaT);
			this._turn_update = (this._character_show ? (this._turn_update + fDeltaT) : 0f);
			if (!this._prelusive)
			{
				if (this._turn_update > this._turn_interval)
				{
					base.ShowCharacterTurn(this._cur_tag);
				}
				else
				{
					if (XSingleton<XGesture>.singleton.OneTouch)
					{
						Ray ray = XSingleton<XScene>.singleton.GameCamera.UnityCamera.ScreenPointToRay(XSingleton<XGesture>.singleton.TouchPosition);
						int num = 1 << LayerMask.NameToLayer("Dummy");
						RaycastHit raycastHit;
						if (Physics.SphereCast(ray, 0.1f, out raycastHit, float.PositiveInfinity, num))
						{
							int num2 = int.Parse(raycastHit.collider.tag);
							if (this._cur_tag == num2)
							{
								base.ShowCharacterTurn(this._cur_tag);
							}
							else
							{
								base.ShowCharacter(num2);
							}
						}
					}
				}
			}
			if (this._prelusive)
			{
				this._character_show = false;
			}
		}

		// Token: 0x0600CACA RID: 51914 RVA: 0x002E0522 File Offset: 0x002DE722
		public override void Play()
		{
			XAutoFade.FadeOut2In(0.5f, 0.5f);
			XSingleton<XTimerMgr>.singleton.SetTimer(0.5f, new XTimerMgr.ElapsedEventHandler(this.EnterFinally), null);
		}

		// Token: 0x0600CACB RID: 51915 RVA: 0x002E0552 File Offset: 0x002DE752
		public void EnterGameWorld(int index)
		{
			XSingleton<XLoginDocument>.singleton.SetBlockUIVisable(true);
			XSingleton<XLoginDocument>.singleton.EnterWorld(index);
		}

		// Token: 0x0600CACC RID: 51916 RVA: 0x002E056D File Offset: 0x002DE76D
		protected void EnterFinally(object o)
		{
			XSingleton<XScene>.singleton.SceneEnterTo(false);
		}

		// Token: 0x0600CACD RID: 51917 RVA: 0x002E057C File Offset: 0x002DE77C
		protected void PresentDone(object o)
		{
			//zcg 跳过 XSingleton<XCutScene>.singleton.Start("CutScene/second_slash_show", false, true);
			int select_slot = XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.SelectedSlot;
			if(select_slot == 0)
			{
				select_slot = 1;
			}
			if (this._auto_enter)
			{
				base.ShowCharacter(select_slot);
			}
			else
			{
				this._token3 = XSingleton<XTimerMgr>.singleton.SetTimer(/*0.433f*/0.1f, new XTimerMgr.ElapsedEventHandler(this.FirstShow), select_slot);
				XSingleton<XLoginDocument>.singleton.ShowSelectCharGerenalUI();
				this._prelusive = false;
			}
		}

		// Token: 0x0600CACE RID: 51918 RVA: 0x002E060C File Offset: 0x002DE80C
		protected void FirstShow(object o)
		{
			base.ShowCharacter((int)o);
		}

		// Token: 0x0600CACF RID: 51919 RVA: 0x002E062C File Offset: 0x002DE82C
		protected override void PrelusiveDone()
		{
			if (this._cur_tag != 0)
			{
				DlgBase<XSelectCharView, SelectCharWindowBehaviour>.singleton.SelectCharIndex = this._cur_tag;
				if (this._auto_enter)
				{
					this.EnterGameWorld(this._cur_tag);
				}
				else
				{
					this._prelusive = false;
					if (this._cur_tag - 1 >= XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.PlayerBriefInfo.Count)
					{
						XSingleton<XDebug>.singleton.AddErrorLog("Character tag ", this._cur_tag.ToString(), " exceeded server PlayerBriefInfo count.", null, null, null);
					}
					else
					{
						if (XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.PlayerBriefInfo[this._cur_tag - 1] == null)
						{
							XSingleton<XLoginDocument>.singleton.ShowSelectCharCreatedUI();
						}
						else
						{
							int level = XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.PlayerBriefInfo[this._cur_tag - 1].level;
							XSingleton<XLoginDocument>.singleton.ShowSelectCharSelectedUI(XSingleton<XAttributeMgr>.singleton.XPlayerCharacters.PlayerBriefInfo[this._cur_tag - 1].name, level);
						}
						XSingleton<XCutScene>.singleton.Start("CutScene/character_show" + XCharStage.role_type[this._cur_tag], false, true);
						this._character_show = true;
					}
				}
			}
		}

		// Token: 0x040059A9 RID: 22953
		private uint _token2 = 0U;

		// Token: 0x040059AA RID: 22954
		private uint _token3 = 0U;

		// Token: 0x040059AB RID: 22955
		private float _turn_interval = 3f;

		// Token: 0x040059AC RID: 22956
		private float _turn_update = 0f;

		// Token: 0x040059AD RID: 22957
		private bool _character_show = false;
	}
}
